package com.heima.wemedia.controller;

import com.heima.model.common.dtos.ResponseResult;
import com.heima.model.common.enums.AppHttpCodeEnum;
import com.heima.model.wemedia.dto.WmLoginDto;
import com.heima.wemedia.service.WmUserService;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * @author itxiaoli
 * @className UserLoginController
 * @description: 自媒体用户登录
 * @date 2022/6/5
 */

@RestController
@Slf4j
@RequestMapping("/login")
public class UserLoginController {

    @Resource
    private WmUserService wmUserService;

    @RequestMapping("/in")
    public ResponseResult login(@RequestBody WmLoginDto wmLoginDto) {
        String name = wmLoginDto.getName();
        String password = wmLoginDto.getPassword();

        if (!StringUtils.isNotBlank(name) || !StringUtils.isNotBlank(password)) {
            return ResponseResult.errorResult(AppHttpCodeEnum.PARAM_REQUIRE);
        }

        return wmUserService.login(wmLoginDto);

    }

}
